package com.googlecode.gmf.data;

import com.googlecode.gmf.data.Web

class WebTest extends GroovyTestCase {

	void testWebHasOneInitialNode() {
		Web web = new Web()
		assertEquals("Web should contain one node initially", 1, web.size())
	}

	void testRemovingAllNodesFromAWeb() {
		Web web = new Web()
		web.emptyWeb()
		assert web.size() == 0
	}
	
	void testYouCanGetAnEmptyWeb() {
		Web web = Web.getAnEmptyWeb()
		assertEquals 0, web.size()
	}
	

	void testAdddingANodeToAWeb() {
		Web web = Web.getAnEmptyWeb()
		web.addNode(new Node(
				title: "Test Node",
				content: "My content"))
		assertEquals 1, web.size()
	}
	
	void testRetrievalOfNodeViaTitle() {
		Web web = Web.getAnEmptyWeb()
		web.addNode(new Node(
				title: "Test Node",
				content: "My content"))
		Node node = web.findByTitle("Test Node")
		assertNotNull "Node is null", node
		
		assertEquals "Test Node", node.title
		assertEquals "My content", node.content
	}
	
	void testMultipleNodeInsertionAndRetrieval() {
		Web web = Web.getAnEmptyWeb()
		web.addNode(new Node(
				title: "Node1",
				content: "Content One"))
				
		Node node = web.findByTitle("Node2")
		
		assertNull "Node find should return null", node
		
		web.addNode(new Node(
				title: "Node2",
				content: "Content Two"))
		node = web.findByTitle("Node2")
		
		assertEquals("Node2", node.title)
		assertEquals("Content Two", node.content)
	}
	
	void testThatNewNodeWithIdenticalTitleIsNotAdded() {
		Web web = Web.getAnEmptyWeb()
		web.addNode(new Node(
				title: "Node1",
				content: "this"))
		web.addNode(new Node(
				title: "Node1",
				content: "that"))
		assertEquals("this", web.findByTitle("Node1").content)
				
	}
}
